package cn.admin.configcenter.registry.common.task;

public abstract class Task {

    private final String taskId;
    private final String taskType;
    private long triggerTimeMs;

    protected Task(String taskId,String taskType,long delayMs) {

        if (delayMs < 0) {
            throw new IllegalArgumentException("delayMs < 0");
        } else {
            this.taskId = taskId;
            this.taskType = taskType;
            this.triggerTimeMs = System.currentTimeMillis() + delayMs;
        }

    }

    protected abstract void merge(Task task);

    public String getType() {
        return this.taskType;
    }

    public String getTaskId() {
        return this.taskId;
    }

    protected boolean shouldProcess() {
        return System.currentTimeMillis() >= this.triggerTimeMs;
    }

    public long getTriggerTimeMs() {
        return this.triggerTimeMs;
    }

    public void setTriggerTimeMs(long triggerTimeMs) {
        this.triggerTimeMs = triggerTimeMs;
    }

}
